package
{
	import as3isolib.geom.Pt;
	
	import flash.display.StageQuality;
	import flash.geom.Point;
	import flash.geom.Vector3D;

	public class MoveGameObjectHelper
	{
		private var m_gameObject:GameObject;
		private var m_originalPosition:Vector3D;
		
		public function MoveGameObjectHelper()
		{
		}
		
		public function isInMovementMode():Boolean{
			return m_originalPosition != null;
		}
		
		public function startMove(store:GameObject):void{
			m_gameObject = store;
			m_originalPosition = m_gameObject.model.location;
		}
		
		public function updateMovePosition(pos:Vector3D):void{
			var extrapolatedPosition:Vector3D = extrapolatePosition(pos);
			m_gameObject.model.location = extrapolatedPosition;
		}
		
		public function endMove():void{
			m_originalPosition = null;
		}
		
		// for now this just snaps
		private function extrapolatePosition(pos:Vector3D):Vector3D{
			var sqSize:int = Constants.SQUARE_SIZE;
			var snappedX:Number = Math.round(pos.x/sqSize)*sqSize;
			var snappedY:Number = Math.round(pos.y/sqSize)*sqSize;
			var snappedZ:Number = Math.round(pos.z/sqSize)*sqSize;
			
			return new Vector3D(snappedX, snappedY, snappedZ);
		}
	}
}